﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

namespace produccion.clases
{
    public class CLSCCPFAC : ObservableObject
    {
        MDOgeneral mod = new MDOgeneral();

        #region Propiedades

        private string _CODCCP_CFC;
        public string CODCCP_CFC
        {
            get { return _CODCCP_CFC; }
            set { _CODCCP_CFC = value; RaisePropertyChangedEvent("CODCCP_CFC"); }
        }

        private string _NOMCCP_CFC;
        public string NOMCCP_CFC
        {
            get { return _NOMCCP_CFC; }
            set { _NOMCCP_CFC = value; RaisePropertyChangedEvent("NOMCCP_CFC"); }
        }

        private string _CTACON_CFC;
        public string CTACON_CFC
        {
            get { return _CTACON_CFC; }
            set { _CTACON_CFC = value; RaisePropertyChangedEvent("CTACON_CFC"); }
        }

        private string _CTAIVA_CFC;
        public string CTAIVA_CFC
        {
            get { return _CTAIVA_CFC; }
            set { _CTAIVA_CFC = value; RaisePropertyChangedEvent("CTAIVA_CFC"); }
        }

        private string _CTACTP_CFC;
        public string CTACTP_CFC
        {
            get { return _CTACTP_CFC; }
            set { _CTACTP_CFC = value; RaisePropertyChangedEvent("CTACTP_CFC"); }
        }

        private string _IVACON_CFC;
        public string IVACON_CFC
        {
            get { return _IVACON_CFC; }
            set { _IVACON_CFC = value; RaisePropertyChangedEvent("IVACON_CFC"); }
        }

        private string _RTECON_CFC;
        public string RTECON_CFC
        {
            get { return _RTECON_CFC; }
            set { _RTECON_CFC = value; RaisePropertyChangedEvent("RTECON_CFC"); }
        }

        private Int32 _BASRTE_CFC ;
        public Int32 BASRTE_CFC
        {
            get { return _BASRTE_CFC; }
            set { _BASRTE_CFC = value; RaisePropertyChangedEvent("BASRTE_CFC"); }
        }

        private double _PORRTE_CFC;
        public double PORRTE_CFC
        {
            get { return _PORRTE_CFC; }
            set { _PORRTE_CFC = value; RaisePropertyChangedEvent("PORRTE_CFC"); }
        }

        private Boolean _EXISTE = false;
        public Boolean EXISTE
        {
            get { return _EXISTE; }
            set
            {
                _EXISTE = value;
                RaisePropertyChangedEvent("EXISTE");
            }
        }

        #endregion

        #region Metodos

        public CLSCCPFAC consultar()
        {
            try
            {
                string query = "select CODCCP_CFC,NOMCCP_CFC,CTACON_CFC,IVACON_CFC,RTECON_CFC,BASRTE_CFC,PORRTE_CFC,CTAIVA_CFC,CTACTP_CFC from ccpfacp where CODCCP_CFC = '" + CODCCP_CFC + "'";
                DataTable dt = mod.consulta(query);
                foreach (DataRow dr in dt.Rows)
                {
                    CODCCP_CFC = dr["CODCCP_CFC"].ToString();
                    NOMCCP_CFC = dr["NOMCCP_CFC"].ToString();
                    CTACON_CFC = dr["CTACON_CFC"].ToString();
                    CTAIVA_CFC = dr["CTAIVA_CFC"].ToString();
                    CTACTP_CFC = dr["CTACTP_CFC"].ToString();
                    IVACON_CFC = dr["IVACON_CFC"].ToString();
                    RTECON_CFC = dr["RTECON_CFC"].ToString();
                    BASRTE_CFC = Convert.ToInt32(dr["BASRTE_CFC"]);
                    PORRTE_CFC = Convert.ToDouble(dr["PORRTE_CFC"].ToString());
                      
                }
                return this;
            }
            catch (Exception ex) { throw ex; }
        }

        public List<CLSCCPFAC> listarConceptosFac()
        {
            try
            {
                string query = "select CODCCP_CFC,NOMCCP_CFC,CTACON_CFC,IVACON_CFC,RTECON_CFC,BASRTE_CFC,PORRTE_CFC,CTAIVA_CFC,CTACTP_CFC from ccpfacp order by NOMCCP_CFC ";
                DataTable dt = mod.consulta(query);
                List<CLSCCPFAC> lista = new List<CLSCCPFAC>();
                foreach (DataRow dr in dt.Rows)
                {
                    lista.Add(new CLSCCPFAC
                    {
                        CODCCP_CFC = dr["CODCCP_CFC"].ToString(),
                        NOMCCP_CFC = dr["NOMCCP_CFC"].ToString(),
                        CTACON_CFC = dr["CTACON_CFC"].ToString(),
                        IVACON_CFC = dr["IVACON_CFC"].ToString(),
                        RTECON_CFC = dr["RTECON_CFC"].ToString(),
                        BASRTE_CFC = Convert.ToInt32(dr["BASRTE_CFC"]),
                        PORRTE_CFC = Convert.ToDouble(dr["PORRTE_CFC"].ToString()),
                        CTAIVA_CFC = dr["CTAIVA_CFC"].ToString(),
                        CTACTP_CFC = dr["CTACTP_CFC"].ToString(),  
                    });
                }
                return lista;
            }
            catch (Exception ex) { throw ex; }
        }

        public DataTable listaConceptosFac()
        {
            try
            {
                string query = "select CODCCP_CFC,NOMCCP_CFC,CTACON_CFC,IVACON_CFC,RTECON_CFC,BASRTE_CFC,PORRTE_CFC,CTAIVA_CFC,CTACTP_CFC from ccpfacp where CODCCP_CFC = '" + CODCCP_CFC + "'";
                return mod.consulta(query);
            }
            catch (Exception ex) { throw ex; }
        }

        public Boolean existe()
        {
            try
            {
                string query = "select count(*) from ccpfacp where CODCCP_CFC = '" + CODCCP_CFC + "'";
                DataTable dt = mod.consulta(query);
                if (dt.Rows[0][0].ToString().Equals("0"))
                    return false;
                else
                    return true;
            }
            catch (Exception ex) { throw ex; }
        }


        #endregion
    }
}
